package com.zuqiuzhandui.liveing.net;

import android.content.Intent;

import com.code19.library.GsonUtil;
import com.code19.library.L;
import com.google.gson.JsonObject;

import org.json.JSONException;
import org.json.JSONObject;

import java.io.IOException;
import java.util.Set;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;
import okhttp3.ResponseBody;

/**
 * Created by yq on 2016-10-12.
 */

public class MyInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        Request request = chain.request();
        Response response = chain.proceed(request);
        ResponseBody body = response.body();
        try {
            JSONObject jsonObject=new JSONObject(body.toString());
            String errorCode = jsonObject.getString("errorCoed");
            if (errorCode.equals("206")||errorCode.equals("207")){
                //token 过期
                Intent intent=new Intent();
                intent.setAction("zuqiuzhandui_action_login");

            }
        } catch (JSONException e) {
            e.printStackTrace();
        }
        return response;
    }


    /**
     * 生成签名sign
     * @param names  参数
     * @return
     */
    private String getSign(Set<String> names) {
        // TODO: 2016-10-12 生成签名的规则
        return null;
    }


}
